﻿using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using RWLib;

namespace RW_GUI
{
    /// <summary>
    /// Interaction logic for AddScenarioWindow.xaml
    /// </summary>
    public partial class AddScenarioWindow : Window
    {
        public bool isValid = false;
        private List<ActionModel> _actions;
        public ScenarioModel Model;
        public AddScenarioWindow(List<ActionModel> actions)
        {
            _actions = actions;
            InitializeComponent();
            LoadCombo();
        }

        private void BtnSaveClick(object sender, RoutedEventArgs e)
        {
            isValid = true;
            var action = CB_Actions.SelectedValue != null ? (string)((ComboBoxItem)CB_Actions.SelectedValue).Content : "";
            Model = new ScenarioModel(action, (int)Slider_Time.Value);
            Close();
        }
        private void BtnCancelClick(object sender, RoutedEventArgs e)
        {
            Close();
        }
        private void SliderTimeValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (sender != null && Txt_Time != null)
                Txt_Time.Content = ((Slider)sender).Value;
        }

        private void LoadCombo()
        {
            foreach (var v in _actions.Select(x => x.Name).Distinct())
            {
                CB_Actions.Items.Add(new ComboBoxItem { Content = v });
            }
            CB_Actions.SelectedIndex = 0;
        }
    }
}
